package org.example.day;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/07/30 9:44
 */
public class Solution2961 {

    public static void main(String[] args) {
        List<Integer> res = new Solution2961().getGoodIndices(new int[][]{{64,8,83,81},{75,46,92,49},{14,89,32,37},{29,15,50,56},{42,47,43,42},{88,22,85,48},{70,8,23,35},{11,25,3,17},{28,69,20,43},{82,42,5,87},{50,87,5,24},{55,19,59,53},{37,29,69,19},{26,25,7,63},{8,14,28,49},{22,25,13,11},{62,78,63,50},{3,67,60,31},{34,40,60,10},{85,62,36,35},{55,19,87,22},{64,8,83,81},{78,49,49,85},{92,51,65,65},{6,44,67,18},{30,58,34,74},{63,80,11,90},{5,13,47,33},{84,71,29,3},{9,77,45,11},{14,23,15,89},{6,31,69,69},{21,84,36,82},{47,85,72,53},{54,81,8,40},{63,80,67,84},{32,28,91,12},{54,18,25,35},{39,69,27,15},{89,10,89,92},{17,66,72,13},{62,39,37,65},{31,84,71,2},{33,89,68,27},{83,54,6,50},{14,49,88,54},{4,43,27,12},{8,4,19,46},{2,18,23,18},{87,51,85,22},{77,3,64,69},{73,31,55,47},{38,85,56,29},{26,60,13,88},{53,7,15,60},{4,15,2,16},{38,86,29,37},{66,2,72,78},{3,75,20,78},{18,87,78,44},{64,83,91,37},{63,20,86,59},{25,35,10,40},{19,20,19,21},{10,39,84,45},{72,34,35,22},{13,36,90,64},{80,26,51,42},{72,3,19,83},{2,34,68,14},{29,52,53,17},{73,91,31,82},{73,84,64,69},{24,83,41,3},{35,51,24,66},{24,21,40,75},{61,9,29,83},{24,58,61,37},{8,51,30,76},{77,16,37,18},{13,58,67,84},{61,2,30,13},{17,66,50,65},{51,76,89,54},{89,18,35,65},{16,57,48,87},{60,43,15,60}}, 34);
        System.out.printf("" + res);
    }

    public List<Integer> getGoodIndices(int[][] variables, int target) {

        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < variables.length; i++) {
            int[] v = variables[i];
            if (pow(pow(v[0], v[1], 10), v[2], v[3]) == target) {
                ans.add(i);
            }
        }
        return ans;
    }

    // 本题 mod 很小，即使平方也不会超过 int 范围，所以不需要用 long
    private int pow(int x, int n, int mod) {
        int res = 1;
        while (n > 0) {
            if (n % 2 > 0) {
                res = res * x % mod;
            }
            x = x * x % mod;
            n /= 2;
        }
        return res;
    }

}
